home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / sidepckt.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  161 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4.  
  5. static struct tilemap *bg_tilemap;
  6. static int flipscreen;
  7.  
  8.  
  9. void sidepckt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  10. {
  11.     int i;
  12.  
  13.     for (i = 0;i < Machine->drv->total_colors;i++)
  14.     {
  15.         int bit0,bit1,bit2,bit3;
  16.  
  17.         /* red component */
  18.         bit0 = (color_prom[0] >> 4) & 0x01;
  19.         bit1 = (color_prom[0] >> 5) & 0x01;
  20.         bit2 = (color_prom[0] >> 6) & 0x01;
  21.         bit3 = (color_prom[0] >> 7) & 0x01;
  22.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  23.         /* green component */
  24.         bit0 = (color_prom[0] >> 0) & 0x01;
  25.         bit1 = (color_prom[0] >> 1) & 0x01;
  26.         bit2 = (color_prom[0] >> 2) & 0x01;
  27.         bit3 = (color_prom[0] >> 3) & 0x01;
  28.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  29.         /* blue component */
  30.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  31.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  32.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  33.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  34.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  35.  
  36.         color_prom++;
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. /***************************************************************************
  43.  
  44.   Callbacks for the TileMap code
  45.  
  46. ***************************************************************************/
  47.  
  48. static void get_tile_info(int tile_index)
  49. {
  50.     unsigned char attr = colorram[tile_index];
  51.     SET_TILE_INFO(0,videoram[tile_index] + ((attr & 0x07) << 8),
  52.             ((attr & 0x10) >> 3) | ((attr & 0x20) >> 5))
  53.     tile_info.flags = TILE_FLIPX | TILE_SPLIT((attr & 0x80) >> 7);
  54. }
  55.  
  56.  
  57.  
  58. /***************************************************************************
  59.  
  60.   Start the video hardware emulation.
  61.  
  62. ***************************************************************************/
  63.  
  64. int sidepckt_vh_start(void)
  65. {
  66.     bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_SPLIT,8,8,32,32);
  67.  
  68.     if (!bg_tilemap)
  69.         return 1;
  70.  
  71.     bg_tilemap->transmask[0] = 0xff; /* split type 0 is totally transparent in front half */
  72.     bg_tilemap->transmask[1] = 0x01; /* split type 1 has pen 1 transparent in front half */
  73.  
  74.     tilemap_set_flip(ALL_TILEMAPS,TILEMAP_FLIPX);
  75.  
  76.     return 0;
  77. }
  78.  
  79.  
  80.  
  81. /***************************************************************************
  82.  
  83.   Memory handlers
  84.  
  85. ***************************************************************************/
  86.  
  87. WRITE_HANDLER( sidepckt_videoram_w )
  88. {
  89.     if (videoram[offset] != data)
  90.     {
  91.         videoram[offset] = data;
  92.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  93.     }
  94. }
  95.  
  96. WRITE_HANDLER( sidepckt_colorram_w )
  97. {
  98.     if (colorram[offset] != data)
  99.     {
  100.         colorram[offset] = data;
  101.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  102.     }
  103. }
  104.  
  105. WRITE_HANDLER( sidepckt_flipscreen_w )
  106. {
  107.     flipscreen = data;
  108.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? TILEMAP_FLIPY : TILEMAP_FLIPX);
  109. }
  110.  
  111.  
  112. /***************************************************************************
  113.  
  114.   Display refresh
  115.  
  116. ***************************************************************************/
  117.  
  118. static void draw_sprites(struct osd_bitmap *bitmap)
  119. {
  120.     int offs;
  121.  
  122.     for (offs = 0;offs < spriteram_size; offs += 4)
  123.     {
  124.         int sx,sy,code,color,flipx,flipy;
  125.  
  126.         code = spriteram[offs+3] + ((spriteram[offs+1] & 0x03) << 8);
  127.         color = (spriteram[offs+1] & 0xf0) >> 4;
  128.  
  129.         sx = spriteram[offs+2]-2;
  130.         sy = spriteram[offs];
  131.  
  132.         flipx = spriteram[offs+1] & 0x08;
  133.         flipy = spriteram[offs+1] & 0x04;
  134.  
  135.         drawgfx(bitmap,Machine->gfx[1],
  136.                 code,
  137.                 color,
  138.                 flipx,flipy,
  139.                 sx,sy,
  140.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  141.         /* wraparound */
  142.         drawgfx(bitmap,Machine->gfx[1],
  143.                 code,
  144.                 color,
  145.                 flipx,flipy,
  146.                 sx-256,sy,
  147.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  148.     }
  149. }
  150.  
  151.  
  152. void sidepckt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  153. {
  154.     tilemap_update(ALL_TILEMAPS);
  155.     tilemap_render(ALL_TILEMAPS);
  156.  
  157.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_BACK);
  158.     draw_sprites(bitmap);
  159.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_FRONT);
  160. }
  161.